package com.chen.service.impl;

import com.chen.converter.SysUserConverter;
import com.chen.dao.SysUserDao;
import com.chen.domain.PageResponse;
import com.chen.domain.SysUser;
import com.chen.domain.SysUserReq;
import com.chen.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * (SysUser)表服务实现类
 * @author: ChenFY
 * @date: 2024/8/20
 */
@Service
@Slf4j
public class SysUserServiceImpl implements SysUserService {
    @Resource
    private SysUserDao sysUserDao;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @Override
    public PageResponse<SysUser> queryByPage(SysUserReq sysUserReq) {
        SysUser sysUser = SysUserConverter.INSTANCE.convertReqToSysUser(sysUserReq);
        PageResponse<SysUser> pageResponse = new PageResponse<>();
        pageResponse.setCurrent(sysUserReq.getPageNo());
        pageResponse.setPageSize(sysUserReq.getPageSize());
        Long pageStart = (sysUserReq.getPageNo() - 1) * sysUserReq.getPageSize();
        long total = this.sysUserDao.count(sysUser);
        List<SysUser> sysUserList = this.sysUserDao.queryAllByLimit(sysUser, pageStart, sysUserReq.getPageSize());
        pageResponse.setTotal(total);
        pageResponse.setRecords(sysUserList);
        return pageResponse;
    }

    /**
     * 查询所以数据
     * @param sysUser 查询条件
     * @return 查询结果
     */
    @Override
    public List<SysUser> queryAll(SysUser sysUser) {
        return sysUserDao.queryAll(sysUser);
    }

    /**
     * 查询数量
     * @param conditions 条件
     * @return 查询结果
     */
    @Override
    public Long queryCount(Map<String, Object> conditions) {
        SysUser sysUser = new SysUser();
        return sysUserDao.count(sysUser);
    }

    /**
     * 批量添加数据
     * @param entities
     * @return
     */
    @Override
    public int insertBatch(List<SysUser> entities) {
        return sysUserDao.insertBatch(entities);
    }
}
